﻿package plugin.business.handler
{
    import cmd.*;
    import com.core.*;
    import com.sh.game.util.*;
    import flash.geom.*;
    import pluginfw.nio.imsg.*;

    public class BusinessHandler extends Object implements IGroupHandler
    {

        public function BusinessHandler()
        {
            return;
        }// end function

        public function dealSimpleMessage(param1:ISimpleMessage) : void
        {
            var _loc_2:Array = null;
            var _loc_3:Point = null;
            var _loc_4:int = 0;
            var _loc_5:Object = null;
            var _loc_6:Object = null;
            var _loc_7:int = 0;
            var _loc_8:int = 0;
            var _loc_9:Object = null;
            var _loc_10:Object = null;
            var _loc_11:int = 0;
            var _loc_12:int = 0;
            var _loc_13:Object = null;
            var _loc_14:Object = null;
            switch(param1.getCmd())
            {
                case CMDBusiness.Error:
                {
                    ModelProxy.change("movetips", "error", param1.getParam());
                    break;
                }
                case CMDBusiness.Reject:
                {
                    ModelProxy.change("zone", "businessReject", param1.getParam());
                    break;
                }
                case CMDBusiness.Request:
                {
                    _loc_2 = ModelProxy.getValue("data", "msgs");
                    if (_loc_2 == null)
                    {
                        _loc_2 = new Array();
                        ModelProxy.change("data", "msgs", _loc_2);
                    }
                    _loc_2.push({type:"business", id:param1.getParam()});
                    ModelProxy.change("business", "request", param1.getParam());
                    break;
                }
                case CMDBusiness.Start:
                {
                    ModelProxy.change("data", "business", this.businessParam(param1.getParam()));
                    _loc_3 = ModelProxy.getValue("data", "screensize");
                    _loc_4 = 200;
                    if (_loc_3)
                    {
                        _loc_4 = int((_loc_3.x - 750) / 2);
                    }
                    ModelProxy.change("plugin", "open", {target:"business", point:new Point(300, 100), top:new Point(_loc_4, 100)});
                    ModelProxy.change("plugin", "open", {target:"bag", point:UIGlobel.pointsDic["bag"], top:new Point(_loc_4 + 375, 100)});
                    break;
                }
                case CMDBusiness.NewItem:
                {
                    ModelProxy.change("data", "business", this.businessParam(param1.getParam()));
                    ModelProxy.change("business", "additem", param1.getParam());
                    break;
                }
                case CMDBusiness.DelItem:
                {
                    ModelProxy.change("data", "business", this.businessParam(param1.getParam()));
                    ModelProxy.change("business", "delitem", param1.getParam());
                    break;
                }
                case CMDBusiness.Lock:
                {
                    ModelProxy.change("data", "business", this.businessParam(param1.getParam()));
                    ModelProxy.change("business", "lock", param1.getParam());
                    break;
                }
                case CMDBusiness.Submit:
                {
                    _loc_5 = this.businessParam(param1.getParam());
                    ModelProxy.change("data", "business", _loc_5);
                    ModelProxy.change("business", "submit", param1.getParam());
                    ModelProxy.change("bag", "businessAddItem", null);
                    break;
                }
                case CMDBusiness.Close:
                {
                    ModelProxy.change("movetips", "error", param1.getParam());
                    ModelProxy.change("plugin", "close", "business");
                    ModelProxy.change("data", "business", null);
                    ModelProxy.change("bag", "businessAddItem", null);
                    break;
                }
                case CMDBusiness.addGold:
                {
                    _loc_6 = param1.getParam();
                    _loc_7 = _loc_6[0];
                    _loc_8 = _loc_6[1];
                    _loc_9 = ModelProxy.getValue("data", "business");
                    if (_loc_9)
                    {
                        if (_loc_9.me.rid == _loc_7)
                        {
                            _loc_9.me.gold = _loc_8;
                        }
                        if (_loc_9.other.rid == _loc_7)
                        {
                            _loc_9.other.gold = _loc_8;
                        }
                    }
                    ModelProxy.change("business", "addGold", param1.getParam());
                    break;
                }
                case CMDBusiness.addMoney:
                {
                    _loc_10 = param1.getParam();
                    _loc_11 = _loc_10[0];
                    _loc_12 = _loc_10[1];
                    _loc_13 = ModelProxy.getValue("data", "business");
                    if (_loc_13)
                    {
                        if (_loc_13.me.rid == _loc_11)
                        {
                            _loc_13.me.money = _loc_12;
                        }
                        if (_loc_13.other.rid == _loc_11)
                        {
                            _loc_13.other.money = _loc_12;
                        }
                    }
                    ModelProxy.change("business", "addMoney", param1.getParam());
                    break;
                }
                case CMDBusiness.noLock:
                {
                    _loc_14 = this.businessParam(param1.getParam());
                    ModelProxy.change("data", "business", _loc_14);
                    ModelProxy.change("business", "nolock", _loc_14);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function dealBufferMessage(param1:IBufferMessage) : void
        {
            return;
        }// end function

        public function dealProxyMessage(param1:IProxyMessage) : void
        {
            return;
        }// end function

        private function businessParam(param1:Object) : Object
        {
            var _loc_4:Object = null;
            var _loc_2:* = new Object();
            var _loc_3:* = UserData.getUserData();
            for each (_loc_4 in param1)
            {
                
                if (_loc_4.rid == _loc_3.rid)
                {
                    _loc_2.me = _loc_4;
                    ModelProxy.change("bag", "businessAddItem", _loc_4.items);
                    continue;
                }
                _loc_2.other = _loc_4;
            }
            return _loc_2;
        }// end function

    }
}
